using NUnit.Framework;

namespace Tests
{
   [TestFixture]
   public class when_using_automatic_collection_properties_in_one_to_many_associations : InMemoryFixturebase
   {
      #region Tests

      [Test]
      public void generic_collections_are_created()
      {
         Assert.That(customer.Orders != null);
      }

      [Test]
      public void non_generic_collections_are_created()
      {
         Assert.That(customer.Contracts != null);
      }

      [Test]
      public void generic_collections_can_be_set()
      {
         customer.Orders.Add(order);
         Assert.That(customer.Orders.Count == 1);
         Assert.AreEqual(order, customer.Orders[0]);
         Assert.AreEqual(customer, order.Customer);
      }

      [Test]
      public void non_generic_collections_can_be_set()
      {
         customer.Contracts.Add(contract);
         Assert.That(customer.Contracts.Count == 1);
         Assert.AreEqual(contract, customer.Contracts[0]);
         Assert.AreEqual(customer, contract.Customer);
      }

      #endregion
   }
   [TestFixture]
   public class when_using_automatic_collection_properties_in_many_to_many_associations : InMemoryFixturebase
   {
      #region Tests

      [Test]
      public void generic_collections_are_created()
      {
         Assert.That(customer.AllOrders != null);
      }

      [Test]
      public void non_generic_collections_are_created()
      {
         Assert.That(customer.AllContracts != null);
      }

      [Test]
      public void generic_collections_can_be_set()
      {
         customer.AllOrders.Add(order);
         Assert.That(customer.AllOrders.Count == 1);
         Assert.AreEqual(order, customer.AllOrders[0]);
         Assert.That(order.AllCustomers.Count == 1);
         Assert.AreEqual(customer, order.AllCustomers[0]);
      }

      [Test]
      public void non_generic_collections_can_be_set()
      {
         customer.AllContracts.Add(contract);
         Assert.That(customer.AllContracts.Count == 1);
         Assert.AreEqual(contract, customer.AllContracts[0]);
         Assert.That(contract.AllCustomers.Count == 1);
         Assert.AreEqual(customer, contract.AllCustomers[0]);
      }
      #endregion
   }
}